#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      Administrator
#
# Created:     14-08-2014
# Copyright:   (c) Administrator 2014
# Licence:     <your licence>
#-------------------------------------------------------------------------------

import httplib2

h = httplib2.Http()
url = 'http://127.0.0.1:8080/weixin'
body = '''<xml>
             <ToUserName><![CDATA[toUser]]></ToUserName>
             <FromUserName><![CDATA[fromUser]]></FromUserName>
             <CreateTime>1348831860</CreateTime>
             <MsgType><![CDATA[text]]></MsgType>
             <Content><![CDATA[this is a test]]></Content>
             <MsgId>1234567890123456</MsgId>
          </xml>'''

def posttext():
    resp, content = h.request(url,
                            "Post", body=body,
                            headers={'content-type':'text/plain'})
    print content

def gettext():
    resp,context = h.request('http://127.0.0.1:12345')
    print context

def parase():
    from xml.etree import ElementTree as ET
    root = ET.fromstring(str(body))

    fromUser = root.findtext(".//FromUserName")
    toUser = root.findtext(".//ToUserName")
    createTime = root.findtext(".//CreateTime")
    msgType = root.findtext(".//MsgType")
    msgId = root.findtext(".//MsgId")

    print fromUser
    print toUser,createTime
    print msgType
    print msgId

def anotherparase():
    from xml.etree import ElementTree as etree
    xml = etree.fromstring(body)
    content = xml.find("Content").text
    msgType = xml.find("MsgType").text
    fromUser = xml.find("FromUserName").text
    toUser = xml.find("ToUserName").text

    print toUser
    print content,msgType,fromUser

def printchris():
    for i in range(10) + [2,2]:
        print ' '*(10-i) + '*'*(2*i + 1)

if __name__ == '__main__':
    printchris()
